package com.xiaoyu.lanling.event.task

import `in`.srain.cube.request.JsonData
import com.xiaoyu.base.app.AppContext
import com.xiaoyu.base.event.BaseJsonEvent
import com.xiaoyu.base.utils.JsonUtil
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.feature.mission.model.MissionBaseItem
import com.xiaoyu.lanling.feature.mission.model.MissionItem
import com.xiaoyu.lanling.feature.mission.model.MissionTitleItem

class MissionListEvent(requestTag: Any, jsonData: JsonData) : BaseJsonEvent(requestTag, jsonData) {

    private val newbieTasks = JsonUtil.convertToList(jsonData.optJson("newbieTasks")) { itemData -> MissionItem(itemData) }
    private val dailyTasks = JsonUtil.convertToList(jsonData.optJson("dailyTasks")) { itemData -> MissionItem(itemData) }

    val list = mutableListOf<MissionBaseItem>().apply {
        if (newbieTasks.isNotEmpty()) {
            add(MissionTitleItem(AppContext.getString(R.string.task_newbie_task_title)))
        }
        addAll(newbieTasks)

        if (dailyTasks.isNotEmpty()) {
            add(MissionTitleItem(AppContext.getString(R.string.task_daily_task_title)))
        }
        addAll(dailyTasks)
    }
}